<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        // 准备原始字符串
        var str = 'abcabcfdsafdhjkhdjkfhalk'
        var obj = {}
        for(var i = 0 ; i < str.length; i ++){
            //将字符串里面的字符一个一个的获取到
            var s = str[i]
            // if(obj[s]){
            //     obj[s]++
            // }else{
            //     obj[s] = 1;
            // }
            obj[s] ?  obj[s]++ : obj[s] = 1;
        }
        //输出
        var ss = "该字符串中"
        for(var key in obj){
            ss += key+"出现"+obj[key]+"次,";
        }
        //找对最后一位的下标
        var index = ss.lastIndexOf(',');
        console.log(ss.substring(0,index));
    </script>
</body>
</html>